﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using SlimCode.Windows.Controls.Mobile;

namespace SlimCode.SlimPasswords
{
  abstract class FileSystemView : ItemView
  {
    public FileSystemView( string fullName )
      : base( string.Empty, ContentAlignmentEx.MiddleLeft, 1.5f )
    {
      this.FullName = fullName;
      this.Text = Path.GetFileName( fullName.TrimEnd( '\\', '/' ) );
    }

    public string FullName { get; private set; }

    public string Folder { get; private set; }
  }

  class FileView : FileSystemView
  {
    public FileView( string fullName )
      : base( fullName )
    {
      this.ImageAlignment = ContentAlignmentEx.MiddleLeft;
    }

    public override Image Image
    {
      get
      {
        if( base.Image == null )
        {
          if( !this.ClientRectangle.IsEmpty )
          {
            if( this.FullName.EndsWith( ".skps", StringComparison.InvariantCultureIgnoreCase ) )
            {
              base.Image = ImageCache.GetPasswordFileImage( this.ClientRectangle.Height - 4 );
            }
            else
            {
              base.Image = ImageCache.GetFileImage( this.ClientRectangle.Height - 4 );
            }
          }
        }

        return base.Image;
      }
      set
      {
        throw new NotSupportedException( "FileView.Image is read-only." );
      }
    }
  }

  abstract class BaseFolderView : FileSystemView
  {
    protected BaseFolderView( string fullName )
      : base( fullName )
    {
      this.ImageAlignment = ContentAlignmentEx.MiddleLeft;
    }
  }

  class FolderView : BaseFolderView
  {
    public FolderView( string fullName )
      : base( fullName )
    {
    }

    public override Image Image
    {
      get
      {
        if( base.Image == null )
        {
          if( !this.ClientRectangle.IsEmpty )
          {
            base.Image = ImageCache.GetFolderImage( this.ClientRectangle.Height - 4 );
          }
        }

        return base.Image;
      }
      set
      {
        throw new NotSupportedException( "FolderView.Image is read-only." );
      }
    }
  }

  class ParentFolderView : BaseFolderView
  {
    public ParentFolderView( string fullName )
      : base( fullName )
    {
      this.ImageAlignment = ContentAlignmentEx.MiddleLeft;
    }

    public override Image Image
    {
      get
      {
        if( base.Image == null )
        {
          if( !this.ClientRectangle.IsEmpty )
          {
            base.Image = ImageCache.GetParentFolderImage( this.ClientRectangle.Height - 4 );
          }
        }

        return base.Image;
      }
      set
      {
        throw new NotSupportedException( "ParentFolderView.Image is read-only." );
      }
    }
  }
}
